package net.hxz.commons.filter;

import net.wy.commons.web.WebContextFactory;
import net.wy.commons.web.WebContextService;

import org.springframework.web.filter.CharacterEncodingFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 12-10-15
 * Time: 上午10:19
 * To change this template use File | Settings | File Templates.
 */
public class SetCharacterEncodingFilter extends CharacterEncodingFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        WebContextService ctx = (WebContextService) WebContextFactory.getWebContext();
        if (((request instanceof HttpServletRequest)) && ((response instanceof HttpServletResponse))) {
            ctx.setRequest((HttpServletRequest) request);
            ctx.setResponse((HttpServletResponse) response);
        }
        super.doFilterInternal(request, response, filterChain);
    }
}
